<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
echo '<ul id="mod_menuTop">';

$query = $db->query("SELECT * FROM {prefix}menu WHERE position = 'top' AND parent = '0' ORDER BY weigh");

while ($data = $query->fetch_object()) {
	
    $childs = $db->query("SELECT * FROM {prefix}menu WHERE parent = '" . $data->id .
        "' AND position = 'top' ORDER BY weigh");
        
    if ((int)$childs->num_rows != 0) {
        $child = "\n<ul class=\"submenu_list\">";
        while ($temp = $childs->fetch_array()) {
            $child .= "\n<li class=\"submenu_item\"><a href=\"{url}" . $temp['href'] . "\">" . $temp['title'] .
                "</a></li>";
        }
        $child .= "\n</ul>\n";
        $class = " submenu";
    }
    
    if (preg_match("/http:/i", $data->href) || preg_match("/www/i", $data->href) ||
        preg_match("/https:/i", $data->href) || preg_match("/ftp:/i", $data->href)) {
        	
        echo "\n" . '<li class="menu_item' . $class . '"><a href="' . $data->href . '">' . $data->
            title . '</a>' . $child . '</li>';
            
    } else {
    	
        echo "\n" . '<li class="menu_item' . $class . '"><a href="{url}' . $data->href . '">' . $data->
            title . '</a>' . $child . '</li>';
            
    }
    
    unset($child, $class);
}

echo '</ul>';
?>